import BaseController from "../../cfw/mvc/BaseController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex } from "../../cfw/tools/Define";
import Player from "../player/Player";
import LoadingController from "../loading/LoadingController";
import SDKManager from "../../sdk/SDKManager";
import LobbyController from "../lobby/LobbyController";
import CrazyClickC from "../crazyClick/CrazyClickC";
import User from "../db/User";
import { BattleID } from "../../sdk/SDKConfig";
import UIManager from "../../cfw/ui/UIManager";


export default class BornController extends BaseController {



    private static ins: BornController;



    static instance() {
        if (!this.ins) {
            this.ins = new BornController()
        }
        return this.ins;
    }

    intoLayer() {

        if (Player.instance().getLevel() > 1) {
            if (SDKManager.getChannel().hasCrazyClick()
                // && User.instance().getLoginCount() > 1
                && SDKManager.getChannel().isOpenStartEgg()) {
                SDKManager.getChannel().battleStart(BattleID.HIT_EGG_TO_LOBBY)
                CrazyClickC.instance().gotoLayer(() => {
                    UIManager.instance().clear()
                    this.gotoLobby()
                })
            } else {
                this.gotoLobby();
            }

        } else {
            ModuleManager.setModuleID(ModuleID.BORN)
            this.pushView('prefabs/BornView', 'BornView', Player.instance(), ModuleManager.getLoader(), UIIndex.ROOT)
        }

    }

    back() {
        this.gotoLobby()
    }

    gotoLobby() {

        let hasSubPackage = SDKManager.getChannel().hasSubPackage()
        if (hasSubPackage) {
            LoadingController.instance().intoLayer(ModuleID.LOBBY, [ModuleID.LOBBY, ModuleID.DECORATION, ModuleID.SMALL_GAME])
        } else {
            LobbyController.instance().intoLayer()
        }



    }

    gotoNext() {
        this.gotoLobby()
    }


}
